<?php

namespace App\Console\Commands\Chanjet;

use App\Http\Controllers\Chanjet\TplusCommonController;
use App\Jobs\SaleGrossProfit;
use App\Models\Chanjet\TplusSaleGrossProfitAnalysisSummary;
use App\Models\Chanjet\TplusToken;
use App\Models\Company;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;

class SaleGrossProfitAnalysis extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:SaleGrossProfitAnalysis';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '获取Tplus数据-销售毛利分析';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $TplusToken = TplusToken::where('is_valid',0)->select(['org_id','access_token'])->get();
        foreach ($TplusToken as $item) {
            if(empty($item['org_id'])){
                continue;
            }
            //CostPriceType 00记账成本 01参考成本 02最新成本 03 平均成本
            $data = [
                'FetchDataSource'=>'00',//00销货单 01销售出库单 02销售发票
                'CostPriceType' => '00',//成本取值 选择记账成本，符合T+存货先进先出 计价方式，计算毛利
                'org_id' => $item['org_id'],
            ];
            \App\Jobs\SaleGrossProfit::dispatch($data);
        }
        return 0;
    }
}
